<template>
	<view class="home">
		<!-- 轮播图 -->
		<swiper :indicator-dots="true" :autoplay="true" :interval="3000" :duration="1000" :circular="true">
			<swiper-item v-for="item in SwiperData" :key="item.id">
				<view class="swiper-item">
					<navigator :url="item.url">
						<image :src="item.img"></image>
					</navigator>
				</view>
			</swiper-item>
		</swiper>
		
		<!-- 导航区域 -->
		<view class="nav">
			<view class="nav_item" v-for="item in navs" :key="item.path" @click="jumpPages(item.path)">
				<view :class="item.icon"></view>
				<text class="font_size">{{item.title}}</text> 
			</view>
		</view>
		
		<!-- 推荐商品区域 -->
		<view class="recommand">
			<view class="title">推荐商品</view>
			<goodList :goods="ShoppingData" @handleNator="handleNator"></goodList>
		</view>
		
	</view>
</template>

<script>
	import goodList from '../../components/goodlist.vue'
	export default {
		data() {
			return {
				// 轮播图数据
				SwiperData:[],
				// 商品数据
				ShoppingData:[],
				// 编程式定义数据
				navs:[
					{
						icon:"iconfont icon-ziyuan",
						title:"社区资源",
						path:"/pages/goods/goods"
					},
					{
						icon:"iconfont icon-guanyuwomen",
						title:"关于我们",
						path:"/pages/contact/contact"
					},
					{
						icon:"iconfont icon-tupian",
						title:"社区图片",
						path:"/pages/pics/pics"
					},
					{
						icon:"iconfont icon-shipin",
						title:"学习视频",
						path:"/pages/study/study"
					}
				]
			}
		},
		onLoad() {
			this.getSwiperData()
			this.getShoppingData()
		},
		methods:{
			// 获取轮播图数据
			async getSwiperData(){
				const res = await this.$request({
					url:"/api/getlunbo"
				})
				this.SwiperData = res.data.message
			},
			// 获取商品数据
			async getShoppingData(){
				const res = await this.$request({
					url:"/api/getgoods?pageindex=1"
				})
				this.ShoppingData = res.data.message
			},
			jumpPages(path){
				uni.navigateTo({
					url:path
				})
			},
			handleNator(id){
				uni.navigateTo({
					url:`../goods_detail/goods_detail?id=${id}`
				})
			}
		},
		components:{
			goodList
		}
	}
</script>

<style lang="less" scoped>
	.home{
		swiper{
			width: 750rpx;
			height: 380rpx;
			swiper-item{
				.swiper-item{
					width: 100%;
					height: 100%;
					navigator{
						width: 100%;
						height: 100%;
						image{
							width: 100%;
							height: 100%;
						}
					}
				}
			}
		}	
	}
	
	.nav{
		display: flex;
		.nav_item{
			flex: 1;
			display: flex;
			justify-content: center;
			align-items: center;
			flex-direction: column;
			.iconfont{
				color: #FFFFFF;
				font-size: 50rpx;
			}
			view{
				display: flex;
				justify-content: center;
				align-items: center;
				width: 120rpx;
				height: 120rpx;
				border-radius: 50%;
				background-color: #b50e03;
				margin-top: 20rpx;
			}
			text{
				margin-top: 10rpx;
				font-size: 25rpx;
				color: #000000;
			}
		}
	}
	
	.recommand{
		overflow: hidden;
		background-color: #eee;
		.title{
			height: 100rpx;
			line-height: 100rpx;
			text-align: center;
			color: #b50e03;
			font-weight: 600;
			letter-spacing: 50rpx;
			margin: 7rpx 0;
			background-color: #fff;
		}
		.recommand_detail_wrap{
			display: flex;
			flex-wrap: wrap;
			padding: 0 15rpx;
		}	
	}
	
</style>

